package com.hceax.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "TestServlet",urlPatterns = {"/test.do"})
public class TestServlet extends HttpServlet  {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1681739795609083728L;

	public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
		
		response.setContentType("text/html;charset = UTF-8");
		PrintWriter out = response.getWriter();
		String grade = "E";
		String quest1 = request.getParameter("quest1");
		String quest2 = request.getParameter("quest2");
		String[] quest3 = request.getParameterValues("quest3");
		String quest4 = request.getParameter("quest4").trim();
		int score = 0;
		if(quest1 != null&&quest1.equals("1")) {
			score = score + 25;
		}
		if(quest2 != null&&quest2.equals("3")) {
			score = score + 25;
		}
		if(quest3 != null&&quest3.length==2&&quest3[0].equals("1")&&quest3[1].equals("3")) {
			score = score + 25;
		}
		if(quest4 != null&&(quest4.equals("HttpServlet")||quest4.equals("javax.servlet.http.HttpServlet"))) {
			score = score + 25;
		}
		if(score>85&&score<=100)
			grade = "A";
		else if(score>75&&score<=85)
			grade = "B";
		else if(score>60&&score<=75)
			grade = "C";
		else if(score>0&&score<=60)
			grade = "D";
		else
			grade = "E";
		out.println("<html><head>");
		out.println("<title>测试结果</title>");
		out.println("</head><body>");
		out.println("你的等级是：<font color=\"#FF0000\">"+grade+"</font>。");
		out.println("</body></html>");
	}
}
